package com.sky.mapper;

import com.sky.entity.Employee;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     * @param username
     * @return
     */
    @Select("select * from employee where username = #{username}")
    Employee getByUsername(String username);

    //插入员工
    @Insert("insert into employee (id, name, username, password, phone, sex, id_number, status, create_time, update_time, create_user, update_user) " +
            " values" +
    "(#{id}, #{name}, #{username},#{password},#{phone},#{sex},#{idNumber},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void insert(Employee employee);

    //分页查询
    //查询总员工数
    @Select("select count(1) from employee")
    int selectCount();
    //查询指定页数的员工
    @Select("select * from employee limit #{start},#{end}")
    List<Employee> select(int start, int end);
    //模糊查询员工数量
    @Select("select count(1) from employee where name like concat('%',#{name},'%')")
    int selectNameCount(String name);
    //查询指定页数的员工
    @Select("select * from employee where name like concat('%',#{name},'%') limit #{start},#{end}")
    List<Employee> selectName(String name,int start, int end);

    //修改employee的字段
    void update(Employee employee);

    //根据id查询员工
    @Select("select * from employee where id = #{id}")
    Employee selectById(Long id);
}
